package com.tomecode.tools.maven.settings.gui.frm;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.grouplayout.GroupLayout;
import org.eclipse.swt.layout.grouplayout.LayoutStyle;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Link;
import org.eclipse.swt.widgets.Shell;

import com.tomecode.tools.maven.settings.gui.images.ImageFactory;
import com.tomecode.tools.maven.settings.gui.utils.GuiUtils;
import com.tomecode.tools.maven.settings.gui.utils.SWTResourceManager;

/**
 * Frm about maven settings editor
 * 
 * @author Tomas Frastia
 * @see http://www.tomecode.com or
 *      http://code.google.com/p/maven-settings-editor/
 * 
 */
public final class FrmAbout extends Dialog {

	private Shell shlAboutMavenSettings;

	/**
	 * Create the dialog.
	 * 
	 * @param parent
	 * @param style
	 */
	public FrmAbout(Shell parent) {
		super(parent, SWT.APPLICATION_MODAL | SWT.DIALOG_TRIM);
		setText("About Maven settings editor");
	}

	/**
	 * Open the dialog.
	 * 
	 * @return the result
	 */
	public final void open() {
		createContents();
		shlAboutMavenSettings.open();
		shlAboutMavenSettings.layout();
		Display display = getParent().getDisplay();
		while (!shlAboutMavenSettings.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
	}

	/**
	 * Create contents of the dialog.
	 */
	private final void createContents() {
		shlAboutMavenSettings = new Shell(getParent(), getStyle());
		shlAboutMavenSettings.setImage(ImageFactory.MAVEN_SETTINGS_EDITOR_16);
		shlAboutMavenSettings.setSize(496, 241);
		shlAboutMavenSettings.setText("About Maven Settings Editor");

		Composite composite = new Composite(shlAboutMavenSettings, SWT.NONE);
		if (GuiUtils.isWindows()) {
			composite.setBounds(0, 0, 490, 194);
		}
		Group group = new Group(composite, SWT.NONE);

		Label label = new Label(group, SWT.NONE);
		label.setImage(ImageFactory.MAVEN_SETTINGS_EDITOR);
		label.setBounds(10, 10, 128, 112);

		Label label_1 = new Label(group, SWT.SEPARATOR | SWT.VERTICAL);
		label_1.setBounds(153, 10, 2, 132);

		Label lblName = new Label(group, SWT.NONE);
		lblName.setFont(SWTResourceManager.getFont("Lucida Grande", 11, SWT.BOLD));
		lblName.setBounds(161, 10, 59, 14);
		lblName.setText("Name");

		Label labelNameValue = new Label(group, SWT.NONE);
		labelNameValue.setBounds(242, 10, 184, 14);
		labelNameValue.setText("Maven Settings Editor");

		Label lblVersion = new Label(group, SWT.NONE);
		lblVersion.setFont(SWTResourceManager.getFont("Lucida Grande", 11, SWT.BOLD));
		lblVersion.setBounds(161, 30, 59, 14);
		lblVersion.setText("Version");

		Label lblBeta = new Label(group, SWT.NONE);
		lblBeta.setBounds(242, 30, 184, 14);
		lblBeta.setText("2.0");

		Label lblBuild = new Label(group, SWT.NONE);
		lblBuild.setFont(SWTResourceManager.getFont("Lucida Grande", 11, SWT.BOLD));
		lblBuild.setBounds(161, 50, 59, 14);
		lblBuild.setText("Build");

		Label labelBuildValue = new Label(group, SWT.NONE);
		labelBuildValue.setBounds(242, 50, 184, 14);

		Label lblcCopyrightEclipse = new Label(group, SWT.NONE);
		lblcCopyrightEclipse.setBounds(161, 70, 304, 32);
		lblcCopyrightEclipse.setText("(c) Copyright TomeCode.com 2010.");

		Link linkProductPage = new Link(group, SWT.NONE);
		linkProductPage.setBounds(161, 108, 304, 14);

		linkProductPage.setText("<a>http://code.google.com/p/maven-settings-editor/</a>");

		Link linkHomePage = new Link(group, SWT.NONE);
		linkHomePage.setBounds(161, 128, 304, 14);
		linkHomePage.setText("<a>http://www.tomecode.com</a>");

		Button btnOk = new Button(composite, SWT.NONE);
		btnOk.addSelectionListener(new SelectionAdapter() {
			@Override
			public final void widgetSelected(SelectionEvent e) {
				shlAboutMavenSettings.close();
			}
		});

		btnOk.setText("Ok");
		GroupLayout gl_shlAboutMavenSettings = new GroupLayout(shlAboutMavenSettings);
		gl_shlAboutMavenSettings.setHorizontalGroup(gl_shlAboutMavenSettings.createParallelGroup(GroupLayout.LEADING).add(composite, GroupLayout.DEFAULT_SIZE, 496, Short.MAX_VALUE));
		gl_shlAboutMavenSettings.setVerticalGroup(gl_shlAboutMavenSettings.createParallelGroup(GroupLayout.LEADING).add(composite, GroupLayout.DEFAULT_SIZE, 216, Short.MAX_VALUE));
		GroupLayout gl_composite = new GroupLayout(composite);
		gl_composite.setHorizontalGroup(gl_composite.createParallelGroup(GroupLayout.LEADING)
				.add(GroupLayout.TRAILING, gl_composite.createSequentialGroup().addContainerGap(387, Short.MAX_VALUE).add(btnOk, GroupLayout.PREFERRED_SIZE, 94, GroupLayout.PREFERRED_SIZE).addContainerGap()).add(group, GroupLayout.DEFAULT_SIZE, 490, Short.MAX_VALUE));
		gl_composite.setVerticalGroup(gl_composite.createParallelGroup(GroupLayout.LEADING).add(
				gl_composite.createSequentialGroup().add(group, GroupLayout.PREFERRED_SIZE, 168, GroupLayout.PREFERRED_SIZE).addPreferredGap(LayoutStyle.UNRELATED).add(btnOk, GroupLayout.PREFERRED_SIZE, 30, GroupLayout.PREFERRED_SIZE).add(7)));
		composite.setLayout(gl_composite);
		shlAboutMavenSettings.setLayout(gl_shlAboutMavenSettings);

	}
}
